/* SettingsService.java
 *
 * Copyright 2011 Aleksey Konovalov
 * All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 * 
 */

package org.jimm.app;

import org.jimm.ui.IconPreferenceScreen;

import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;

public final class SettingsActivity extends PreferenceActivity {
	
	public static final String LOG_TAG = "Jimm:SettingActivity";
	public static String lang;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.settings);
		Resources res = getResources();
		
		IconPreferenceScreen accounts = (IconPreferenceScreen) findPreference("accounts");
		IconPreferenceScreen contactlist = (IconPreferenceScreen) findPreference("ContactList");
		IconPreferenceScreen chat = (IconPreferenceScreen) findPreference("Chat");
		IconPreferenceScreen notify = (IconPreferenceScreen) findPreference("Notifications");
		IconPreferenceScreen app = (IconPreferenceScreen) findPreference("Application");
		
		Drawable accountsIcon = res.getDrawable(R.drawable.ic_setting_accounts);
		Drawable contactlistIcon = res.getDrawable(R.drawable.ic_setting_contact_list);
		Drawable chatIcon = res.getDrawable(R.drawable.ic_setting_chat);
		Drawable notifyIcon = res.getDrawable(R.drawable.ic_setting_notify);
		Drawable appIcon = res.getDrawable(R.drawable.ic_setting_app);
		
		accounts.setIcon(accountsIcon);
		contactlist.setIcon(contactlistIcon);
		chat.setIcon(chatIcon);
		notify.setIcon(notifyIcon);
		app.setIcon(appIcon);
;
		
		Preference accountsPref = findPreference("accounts");
		Preference contactlistPref = findPreference("ContactList");
		Preference chatPref = findPreference("Chat");
		Preference notifyPref = findPreference("Notifications");
		Preference appPref = findPreference("Application");
		accountsPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
			@Override
			public boolean onPreferenceClick(Preference preference) {
				startActivity(new Intent(SettingsActivity.this, AccountsEditorActivity.class));
				ContactListActivity.ShowMenu=true;
				return true;
			}
		});
		contactlistPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
			@Override
			public boolean onPreferenceClick(Preference preference) {
				startActivity(new Intent(SettingsActivity.this, SettingsContactListActivity.class));
				return true;
			}
		});
		chatPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
			@Override
			public boolean onPreferenceClick(Preference preference) {
				startActivity(new Intent(SettingsActivity.this, SettingsChatActivity.class));
				return true;
			}
		});
		notifyPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
			@Override
			public boolean onPreferenceClick(Preference preference) {
				startActivity(new Intent(SettingsActivity.this, SettingsNotificationsActivity.class));
				return true;
			}
		});
		appPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
			@Override
			public boolean onPreferenceClick(Preference preference) {
				startActivity(new Intent(SettingsActivity.this, SettingsApplicationActivity.class));
				return true;
			}
		});
	}
}
